package com.th.supcom.pds.config.client.widget;

import java.util.List;

import net.carefx.framework.container.client.constant.FrameworkConstants;
import net.carefx.framework.container.client.context.AppContext;

import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.th.supcom.pds.common.client.model.icon.Resources;
import com.th.supcom.pds.config.client.common.PdsConfigEnableEnum;
import com.th.supcom.pds.config.client.model.PhamDispensaryConfigModel;

public final class PhamConfigWidgetUtils
{

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, XuNuo Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

    /**
     * 校验过滤器输入是否存在
     * 
     * @param record
     * @param filter
     * @return
     */
    public static boolean checkContainFilter (final PhamDispensaryConfigModel record, final String filter)
    {
        if ((record.getDeptPinyinCode () != null && record.getDeptPinyinCode ().contains (filter))
            || record.getShiftName () != null && record.getShiftName ().contains (filter)
            || record.getPhamType () != null && record.getPhamType ().contains (filter))
        {
            return true;
        }
        return false;
    }

    /**
     * 生成是否启用radio
     * 
     * @param enableType
     * @param enableRadio
     * @param disableRadio
     * @param enableTypeName 启用类型名称
     */
    public static void generateEnableRadio (final RadioGroup enableType, final Radio enableRadio,
                                            final Radio disableRadio, final String enableTypeName)
    {
        enableType.setFieldLabel (FrameworkConstants.FORM_MUST_FILL_TIP + enableTypeName + "启用");

        enableRadio.setBoxLabel ("是");
        enableRadio.setValueAttribute (PdsConfigEnableEnum.Enable.getCode () + "");
        enableRadio.setValue (true);

        disableRadio.setBoxLabel ("否");
        disableRadio.setValueAttribute (PdsConfigEnableEnum.Disable.getCode () + "");
        disableRadio.setValue (false);

        enableType.add (enableRadio);
        enableType.add (disableRadio);
        enableType.setValue (enableRadio);
    }

    /**
     * 生成grid序号列
     * 
     * @param configs
     * @param column
     */
    public static void generateGridSeq (final List <ColumnConfig> configs, final ColumnConfig column)
    {
        column.setAlignment (HorizontalAlignment.RIGHT);
        final RowNumberer r = new RowNumberer ();
        r.setWidth (20);
        configs.add (r);
    }

    /**
     * 生成界面toolBar
     * 
     * @param addButton
     * @param editButton
     * @param removeButton
     * @param refreshButton
     * @return
     */
    public static ToolBar generateToolBar (final Button addButton, final Button editButton, final Button removeButton,
                                           final Button refreshButton)
    {
        final ToolBar toolBar = new ToolBar ();
            addButton.setText ("新增(A)");
            addButton.setIcon (Resources.s_ICONS.add ());
            toolBar.add (addButton); 
         // 分隔符
            toolBar.add (new SeparatorToolItem ());
        
        editButton.setText ("编辑(X)");
        editButton.setIcon (Resources.s_ICONS.edit ());
        toolBar.add (editButton);

        // 分隔符
        toolBar.add (new SeparatorToolItem ());

        removeButton.setText ("删除(D)");
        removeButton.setIcon (Resources.s_ICONS.delete ());
        toolBar.add (removeButton);
        // 分隔符
        toolBar.add (new SeparatorToolItem ());

        // 刷新按钮
        refreshButton.setText ("刷新(F)");
        refreshButton.setIcon (GXT.IMAGES.paging_toolbar_refresh ());
        toolBar.add (refreshButton);

        toolBar.add (new FillToolItem ());
        return toolBar;
    }
    public static int getIsGlobal(){
        return AppContext.get ().get ("isGlobal");
    }
    private PhamConfigWidgetUtils ()
    {

    }
}
